package community;

import java.io.*;
import java.net.*;
import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;

import model.*;

import org.apache.struts.action.*;
import org.apache.struts.actions.*;

import board.*;

import util.*;

public class CommunityInfo extends DispatchAction{
	
	//커뮤니티 관리자 페이지 호출 하였을때 실행되는 메소드
	public ActionForward adminMain(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		CommunityGo.setMemberCommunity(request);
		ActionForward actionforward = new ActionForward();
		actionforward.setPath("/communityinfo.do?method=infoForm&cono="+request.getParameter("cono"));
		return actionforward;	
	}
	
	//커뉴니티 개설 신청 요청시 실행되는 메소드(폼 제공)
	public ActionForward createForm(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		CommunityForm coForm = (CommunityForm)form;
		
		//커뮤니티 카테고리 정보취득----------------------------
		CommunityCategoryDAO ccDAO = new CommunityCategoryDAO();
		Vector<CommunityCategory> ca = ccDAO.getList();
		//정의된 카테고리를 액션폼에 셋팅
		coForm.setCategorys(ca);
		
		CommunityDAO coDAO = new CommunityDAO();
		MemberCommunityDAO mcDAO = new MemberCommunityDAO();
		
		HttpSession session = request.getSession();
		User user = (User)session.getAttribute("user");
		
		if(session.getAttribute("user")!=null){
			if(user.isLogon()){
				coForm.setMemberCommunitys(mcDAO.getMemberCommunity(user.getMid()));
			}else{
				coForm.setMemberCommunitys(mcDAO.getMemberCommunity());
			}
		}
		
		return mapping.findForward("createform");
	
	}
	
	//커뮤니티 정보변경 호출시 실행되는 메소드(폼 제공)
	public ActionForward infoForm(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		CommunityForm coForm = (CommunityForm)form;
		
		//커뮤니티 카테고리 정보취득----------------------------
		CommunityCategoryDAO ccDAO = new CommunityCategoryDAO();
		Vector<CommunityCategory> ca = ccDAO.getList();
		//커뮤니티 카테고리 액션폼에 셋팅
		coForm.setCategorys(ca);
		coForm.setCono(Integer.parseInt(request.getParameter("cono")));
		
		CommunityDAO coDAO = new CommunityDAO();
		MemberCommunityDAO mcDAO = new MemberCommunityDAO();
		
		HttpSession session = request.getSession();
		User user = (User)session.getAttribute("user");
		
		if(session.getAttribute("user")!=null){
			if(user.isLogon()){
				coForm.setMemberCommunitys(mcDAO.getMemberCommunity(user.getMid()));
			}else{
				coForm.setMemberCommunitys(mcDAO.getMemberCommunity());
			}
		}
		
		Community comm = new Community();
		comm.setCono(coForm.getCono());
		
		//정보변경하고 싶은 커뮤니티의 값을 액션폼에 셋팅
		comm = coDAO.getCommunity(comm);
		coForm.setCono(comm.getCono());
		coForm.setConame(comm.getConame());
		coForm.setCoopen(comm.getCoopen());
		coForm.setCologoofn(comm.getCologoofn());
		coForm.setCologosfn(comm.getCologosfn());
		coForm.setCopoptext(comm.getCopoptext());
		coForm.setCopopwidth(comm.getCopopwidth());
		coForm.setCopopheight(comm.getCopopheight());
		coForm.setCoguide(comm.getCoguide());
		coForm.setCcno(comm.getCcno());
		
		//커뮤니티가 가지고 있는 링크를 가지고 와서 액션폼에 셋팅
		CommunityLinkDAO clDAO = new CommunityLinkDAO();
		coForm.setCommunityLinks(clDAO.getCommunityLinks(comm.getCono()));
		coForm.setLinksize(coForm.getCommunityLinks().size());
		
		
		return mapping.findForward("infoform");
	
	}
	
	//커뮤니티 삭제 요청시 실행되는 메소드(폼 제공)
	public ActionForward delForm(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		CommunityForm coForm = (CommunityForm)form;
		
		int cono = Integer.parseInt(request.getParameter("cono"));
		coForm.setCono(cono);
		
		return mapping.findForward("delform");
	}
	
	//커뮤니티 개설 신청에서 신청 요청이 왔을때 실행되는 메소드
	public ActionForward receiveData(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		CommunityForm coForm = (CommunityForm)form;
		Community community = new Community();
		
		String originalName = coForm.getFile().getFileName();
		String savedName = null;
		String logosfn = null;
		
		//커뮤니티 로고를 올렸을 경우 실행된다
		if(originalName.equals("")){
			originalName = null;
		}else{
			ServletContext sc = request.getSession().getServletContext();			
			String fileName = sc.getRealPath("/uploadfiles/"+originalName);
			InputStream is = coForm.getFile().getInputStream();
			savedName = FileSaver.save(fileName, is);
			logosfn = savedName.substring(savedName.lastIndexOf("\\")+1);			
		}
		
		//신청요청한 정보들을 DTO에 저장한다
		community.setCono(coForm.getCono());
		community.setConame(coForm.getConame());
		community.setCoopen(coForm.getCoopen());
		community.setCologoofn(originalName);
		community.setCologosfn(logosfn);
		community.setCopoptext(coForm.getCopoptext());
		community.setCopopwidth(coForm.getCopopwidth());
		community.setCopopheight(coForm.getCopopheight());
		community.setCoguide(coForm.getCoguide());
		community.setCcno(coForm.getCcno());
		
		CommunityDAO coDAO = new CommunityDAO();
		//데이타베이스에 저장한다.
		coDAO.insert(community);
		
		community = coDAO.getNewCreateCommunity();
		
		//신청한 유저의 아이디를 커뮤니티 관리자 등급으로 가입시킨다.
		String mid = request.getParameter("mid");
		MemberCommunity mc = new MemberCommunity();
		mc.setCono(community.getCono());
		mc.setLvno(7);
		mc.setMcnick(mid);
		mc.setMid(mid);
		
		MemberCommunityDAO mcDAO = new MemberCommunityDAO();
		mcDAO.insert(mc);
		
		//커뮤니티 링크를 처리하는 부분
		int linkcount = Integer.parseInt(request.getParameter("linkcount"));
		String name = "linkname";
		String address = "linkaddress";
		CommunityLink cl = new CommunityLink();
		CommunityLinkDAO clDAO = new CommunityLinkDAO();
		cl.setCono(community.getCono());
		
		String linkname="";
		String linkaddress="";
		
		//등록한 요청 수 만큼 데이타베이스에 저장한다.
		for(int i=0;i<linkcount;i++){			
			linkname = request.getParameter(name+(i+1));
			linkaddress = request.getParameter(address+(i+1));			
			if( !linkname.equals("") && linkname!=null){
				if( !linkaddress.equals("") && linkaddress!=null){
					cl.setLinkname(linkname);
					cl.setLinkaddress(linkaddress);
					clDAO.insert(cl);					
				}			
			}
		}
		
		
		return mapping.findForward("ok");
	
	}
	
	//커뮤니티 정보변경에서 수정시 실행하는 메소드
	public ActionForward receiveInfo(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		
		CommunityForm coForm = (CommunityForm)form;
		Community community = new Community();
		
		String originalName = coForm.getFile().getFileName();
		String savedName = null;
		String logosfn = coForm.getCologosfn();
		
		//변경 요청한 값들을 DTO에 저장
		community.setCono(coForm.getCono());
		community.setConame(coForm.getConame());
		community.setCoopen(coForm.getCoopen());
		community.setCopoptext(coForm.getCopoptext());
		community.setCopopwidth(coForm.getCopopwidth());
		community.setCopopheight(coForm.getCopopheight());
		community.setCoguide(coForm.getCoguide());
		community.setCcno(coForm.getCcno());
		
		CommunityDAO coDAO = new CommunityDAO();
		
		if(coForm.getCologoofn()==null){
			coForm.setCologoofn("");
		}
		
		//로고파일이 저장되었을때 실행되는 부분
		if(!coForm.getCologoofn().equals(originalName)){
			//새로운 로고파일을 저장한다.
			ServletContext sc = request.getSession().getServletContext();			
			String fileName = sc.getRealPath("/uploadfiles/"+originalName);
			InputStream is = coForm.getFile().getInputStream();
			savedName = FileSaver.save(fileName, is);
			logosfn = savedName.substring(savedName.lastIndexOf("\\")+1);
			community.setCologoofn(originalName);
			community.setCologosfn(logosfn);
			coDAO.updateCoLogo(community);
			
			//기존에 있던 로고파일을 삭제한다.
			String pathName = sc.getRealPath("/uploadfiles/" + coForm.getCologosfn());
			File file = new File(pathName);
			file.delete();
		}
		
		//부분별로 수정한다.
		coDAO.updateCoGudie(community);
		coDAO.updateCoOpen(community);
		coDAO.updateCoPop(community);
		
		
		//링크 수정되었을때
		int linkcount = Integer.parseInt(request.getParameter("linkcount"));
		int linkcount2 = Integer.parseInt(request.getParameter("linkcount2"));
		String name = "linkname";
		String address = "linkaddress";
		
		CommunityLink cl = new CommunityLink();
		CommunityLinkDAO clDAO = new CommunityLinkDAO();
		cl.setCono(community.getCono());
		
		String linkname="";
		String linkaddress="";
		
		String isLink = request.getParameter("isLink");
		
		for(int i=0;i<linkcount;i++){
			linkname = request.getParameter(name+(i+1));
			linkaddress = request.getParameter(address+(i+1));
			//기존에 링크가 있는지 없는지를 판단
			if(isLink.equals("true")){
				if( !linkname.equals("") && linkname!=null){
					if( !linkaddress.equals("") && linkaddress!=null){
						//새로 입력하는 링크라면 추가를 시키고
						if(i>=linkcount2){
							cl.setLinkname(linkname);
							cl.setLinkaddress(linkaddress);
							clDAO.insert(cl);			
						//기존에 있던 링크라면 수정을 한다.
						}else{
							int linkno = Integer.parseInt(request.getParameter("linkno"+(i+1)));
							cl.setLinkno(linkno);
							cl.setLinkname(linkname);
							cl.setLinkaddress(linkaddress);
							clDAO.update(cl);
						}
					}			
				}
			//전부 새로 추가시키는 것이라면 전부 데이타베이스에 추가
			}else{
				if( !linkname.equals("") && linkname!=null){
					if( !linkaddress.equals("") && linkaddress!=null){
						cl.setLinkname(linkname);
						cl.setLinkaddress(linkaddress);
						clDAO.insert(cl);
					}			
				}
			}
		}
				
		
		ActionForward actionforward = new ActionForward();
		actionforward.setPath("/community.do?cono="+community.getCono());
		return actionforward;	
	
	}
	
	//커뮤니티 회원 관리 요청시 발생하는 메소드
	public ActionForward getMember(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		CommunityForm coForm = (CommunityForm)form;
		int cono = Integer.parseInt(request.getParameter("cono"));
		
		MemberCommunityDAO mcDAO = new MemberCommunityDAO();
		
		long totalRows = mcDAO.getTotalRows(cono);
		Pager pager = new Pager();
		pager.init(request, totalRows, 10, 5);
		
		coForm.setMemberCommunitys(mcDAO.getMemberCommunityList(cono, pager.getCurrentPage(), pager.getRowsPerPage()));
			
		return mapping.findForward("member");
	
	}
	
	//커뮤니티 회원의 등급을 변경시킬때 발생하는 메소드
	public ActionForward memberupdate(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
				
		String mid = request.getParameter("mid");
		int lvno = Integer.parseInt(request.getParameter("lvno"));
		int cono = Integer.parseInt(request.getParameter("cono"));
		
		MemberCommunityDAO mcDAO = new MemberCommunityDAO();
		MemberCommunity mc = new MemberCommunity();
		mc.setMid(mid);
		mc.setLvno(lvno);
		mc.setCono(cono);
		
		mcDAO.updateLevel(mc);
		
		ActionForward actionforward = new ActionForward();
		actionforward.setPath("/communityinfo.do?method=getMember&cono="+cono);
		return actionforward;
	
	}
	
	//커뮤니티 회원을 탈퇴시킬때 실행되는 메소드
	public ActionForward memberdelete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {		
		
		String mid = request.getParameter("mid");
		int cono = Integer.parseInt(request.getParameter("cono"));
		
		MemberCommunityDAO mcDAO = new MemberCommunityDAO();
		MemberCommunity mc = new MemberCommunity();
		mc.setMid(mid);
		mc.setCono(cono);
		
		mcDAO.delete(mc);
		
		ActionForward actionforward = new ActionForward();
		actionforward.setPath("/communityinfo.do?method=getMember&cono="+cono);
		return actionforward;
	
	}

	//기존에 있던 링크를 삭제할 때 실행되는 메소드
	public ActionForward linkdelete(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {		
		
		int linkno = Integer.parseInt(request.getParameter("linkno"));
		int cono = Integer.parseInt(request.getParameter("cono"));
		
		CommunityLink cl = new CommunityLink();
		CommunityLinkDAO clDAO = new CommunityLinkDAO();
		
		cl.setLinkno(linkno);
		
		clDAO.delete(cl);
		
		ActionForward actionforward = new ActionForward();
		actionforward.setPath("/communityinfo.do?method=infoForm&cono="+cono);
		return actionforward;
	
	}
	
	//커뮤니티 메뉴관리 요청시 실행되는 메소드
	public ActionForward getMenu(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {		
		
		return mapping.findForward("menu");
	
	}
	
	//커뮤니티 메뉴 중 자유게시판 명칭을 수정할때 실행되는 메소드
	public ActionForward fbChangeName(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {		
		
		String bname = URLDecoder.decode(request.getParameter("bname"),"utf-8");
		int cono = Integer.parseInt(request.getParameter("cono"));
		String newname = URLDecoder.decode(request.getParameter("newname"),"utf-8");
		
		FreeBoardAction fbAction = new FreeBoardAction();
		
		fbAction.changeBoardName(cono, bname, newname);
		
		changeMenu(cono, request);	
		
		ActionForward actionforward = new ActionForward();
		actionforward.setPath("/communityinfo.do?method=getMenu&cono="+cono);
		return actionforward;
	
	}
	
	//커뮤니티 메뉴 중 자유게시판을 삭제할때 실행되는 메소드
	public ActionForward fbDel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {		
		
		String bname = URLDecoder.decode(request.getParameter("bname"),"utf-8");
		int cono = Integer.parseInt(request.getParameter("cono"));
		
		FreeBoardDAO fbDAO = new FreeBoardDAO();
		
		fbDAO.deleteBoard(cono, bname);
		
		changeMenu(cono, request);	
		
		
		ActionForward actionforward = new ActionForward();
		actionforward.setPath("/communityinfo.do?method=getMenu&cono="+cono);
		return actionforward;
	
	}
	
	//커뮤니티 메뉴 중 자유게시판을 추가할때 실행되는 메소드
	public ActionForward fbNew(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {		
		
		String bname = URLDecoder.decode(request.getParameter("bname"),"utf-8");
		int cono = Integer.parseInt(request.getParameter("cono"));
		
		FreeBoardAction fbAction = new FreeBoardAction();
		
		
		User user = (User)request.getSession().getAttribute("user");
		
		fbAction.createNewBoard(cono, bname, user.getMid());
		
		changeMenu(cono, request);	
		
		ActionForward actionforward = new ActionForward();
		actionforward.setPath("/communityinfo.do?method=getMenu&cono="+cono);
		return actionforward;
	
	}
	
	//커뮤니티 메뉴 중 자료실 명칭을 수정할때 실행되는 메소드
	public ActionForward dbChangeName(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {		
		
		String bname = URLDecoder.decode(request.getParameter("bname"),"utf-8");
		int cono = Integer.parseInt(request.getParameter("cono"));
		String newname = URLDecoder.decode(request.getParameter("newname"),"utf-8");
		
		DataBoardDAO dbDAO = new DataBoardDAO();
		
		dbDAO.setBoardName(cono, bname, newname);
		
		changeMenu(cono, request);	
		
		
		ActionForward actionforward = new ActionForward();
		actionforward.setPath("/communityinfo.do?method=getMenu&cono="+cono);
		return actionforward;
	
	}
	
	//커뮤니티 메뉴 중 자료실을 삭제할때 실행되는 메소드
	public ActionForward dbDel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {		
		
		String bname = URLDecoder.decode(request.getParameter("bname"),"utf-8");
		int cono = Integer.parseInt(request.getParameter("cono"));
		
		DataBoardDAO dbDAO = new DataBoardDAO();
		
		Vector<String> savefiles = dbDAO.getSavedFileNames(cono, bname);
		ServletContext sc = request.getSession().getServletContext();
		for(int i=0;i<savefiles.size();i++){
			String savename = savefiles.get(i);
			if(savename!=null){
				String pathName = sc.getRealPath("/uploadfiles/" + savename);
				File file = new File(pathName);
				file.delete();
			}
		}
		
		dbDAO.deleteBoard(cono, bname);
		
		changeMenu(cono, request);	
		
		
		ActionForward actionforward = new ActionForward();
		actionforward.setPath("/communityinfo.do?method=getMenu&cono="+cono);
		return actionforward;
	
	}
	
	//커뮤니티 메뉴 중 자료실을 추가할때 실행되는 메소드
	public ActionForward dbNew(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {		
		
		String bname = URLDecoder.decode(request.getParameter("bname"),"utf-8");
		int cono = Integer.parseInt(request.getParameter("cono"));
		
		DataBoardDAO dbDAO = new DataBoardDAO();
		
		User user = (User)request.getSession().getAttribute("user");
		DataBoard db = new DataBoard();
		db.setCono(cono);
		db.setDbname(bname);
		db.setMid(user.getMid());
		db.setDbtitle("게시판 생성");
		//@@ db.setDbcontent("");
		db.setDbcontent("자료실 게시판 생성");
		db.setDbsfn(null);
		db.setDbofn(null);
		db.setDbfsize(0);
		db.setDbftype(null);
		
		dbDAO.insert(db);	
		
		changeMenu(cono, request);	
		
		ActionForward actionforward = new ActionForward();
		actionforward.setPath("/communityinfo.do?method=getMenu&cono="+cono);
		return actionforward;
	
	}
	
	//커뮤니티 메뉴 중 갤러리 명칭을 수정할때 실행되는 메소드
	public ActionForward pbChangeName(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {		
		
		String bname = URLDecoder.decode(request.getParameter("bname"),"utf-8");
		int cono = Integer.parseInt(request.getParameter("cono"));
		String newname = URLDecoder.decode(request.getParameter("newname"),"utf-8");
		
		PhotoBoardDAO pbDAO = new PhotoBoardDAO();
		
		pbDAO.setBoardName(cono, bname, newname);
		
		changeMenu(cono, request);	
		
		
		ActionForward actionforward = new ActionForward();
		actionforward.setPath("/communityinfo.do?method=getMenu&cono="+cono);
		return actionforward;
	
	}
	
	//커뮤니티 메뉴 중 갤러리을 삭제할때 실행되는 메소드
	public ActionForward pbDel(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {		
		
		String bname = URLDecoder.decode(request.getParameter("bname"),"utf-8");
		int cono = Integer.parseInt(request.getParameter("cono"));
		
		PhotoBoardDAO pbDAO = new PhotoBoardDAO();
		
		Vector<String> savefiles = pbDAO.getPhotoFileNames(cono, bname);
		ServletContext sc = request.getSession().getServletContext();
		for(int i=0;i<savefiles.size();i++){
			String savename = savefiles.get(i);
			if(savename!=null){
				String pathName = sc.getRealPath("/uploadfiles/" + savename);
				File file = new File(pathName);
				file.delete();
			}
		}
		
		pbDAO.deleteBoard(cono, bname);
		
		changeMenu(cono, request);	
		
		
		ActionForward actionforward = new ActionForward();
		actionforward.setPath("/communityinfo.do?method=getMenu&cono="+cono);
		return actionforward;
	
	}
	
	//커뮤니티 메뉴 중 갤러리을 추가할때 실행되는 메소드
	public ActionForward pbNew(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {		
		
		String bname = URLDecoder.decode(request.getParameter("bname"),"utf-8");
		int cono = Integer.parseInt(request.getParameter("cono"));
		
		PhotoBoardDAO pbDAO = new PhotoBoardDAO();
		PhotoBoard pb = new PhotoBoard();
			
		User user = (User)request.getSession().getAttribute("user");
		
		pb.setCono(cono);
		pb.setPbname(bname);
		pb.setMid(user.getMid());
		pb.setPbtitle("게시판 생성");
		//@@ pb.setPbcontent("");
		pb.setPbcontent("포토게시판 생성");
		pb.setPbsfn("photodefault.jpg");
		pb.setPbofn("photodefault.jpg");
		pb.setPbfsize(35694);
		pb.setPbwidth(120);
		pb.setPbheight(120);
		
		pbDAO.insert(pb);
		
		changeMenu(cono, request);	
		
		ActionForward actionforward = new ActionForward();
		actionforward.setPath("/communityinfo.do?method=getMenu&cono="+cono);
		return actionforward;
	
	}
	
	//커뮤니티 삭제 메소드
	public ActionForward delComm(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception {
		int cono = Integer.parseInt(request.getParameter("cono"));
		ServletContext sc = request.getSession().getServletContext();
		
		//커뮤니티에 해당하는 DataBoard 내용 삭제
		DataBoardDAO dbDAO = new DataBoardDAO();
		//해당 자료들 삭제
		Vector<String> dbsavefiles = dbDAO.getSavedFileNames(cono);
		for(int i=0;i<dbsavefiles.size();i++){
			String savename = dbsavefiles.get(i);
			if(savename!=null){
				String pathName = sc.getRealPath("/uploadfiles/" + savename);
				File file = new File(pathName);
				file.delete();
			}
		}
		//DB 자료 삭제
		dbDAO.delete(cono);
		
		//커뮤니티에 해당하는 PhotoBoard 내용 삭제
		PhotoBoardDAO pbDAO = new PhotoBoardDAO();
		//해당 자료들 삭제
		Vector<String> pbsavefiles = pbDAO.getPhotoFileNames(cono);
		for(int i=0;i<pbsavefiles.size();i++){
			String savename = pbsavefiles.get(i);
			if(savename!=null){
				String pathName = sc.getRealPath("/uploadfiles/" + savename);
				File file = new File(pathName);
				file.delete();
			}
		}
		//DB 자료 삭제
		pbDAO.delete(cono);
		
		//커뮤니티에 해당하는 FreeBoard 내용 삭제
		FreeBoardDAO fbDAO = new FreeBoardDAO();
		fbDAO.delete(cono);		
		
		//커뮤니티에 해당하는  NoticeBoard 내용 삭제
		NoticeBoardDAO nbDAO = new NoticeBoardDAO();
		nbDAO.delete(cono);
		
		//커뮤니티에 가입되어있는 사용자 삭제
		MemberCommunityDAO mcDAO = new MemberCommunityDAO();
		mcDAO.delete(cono);
		
		//커뮤니티에 해당하는 링크 삭제
		CommunityLinkDAO clDAO = new CommunityLinkDAO();
		clDAO.delete(cono);
		
		//커뮤니티 삭제
		CommunityDAO coDAO = new CommunityDAO();
		//커뮤니티 로고 삭제
		String logosfn = coDAO.getLogoSaveName(cono);
		if(logosfn!=null){
			String logopathName = sc.getRealPath("/uploadfiles/" + logosfn);
			File file = new File(logopathName);
			file.delete();
		}
		coDAO.delete(cono);
		
		
		ActionForward actionforward = new ActionForward();
		actionforward.setPath("/communitymain.do");
		return actionforward;
	}
	
	//메뉴를 수정할 때 마다 실행하는 메소드
	//변경된 메뉴를 세션개체에 저장하는 메소드
	public void changeMenu(int cono,HttpServletRequest request){
		Menu menu = (Menu)request.getSession().getAttribute("menu");;
		FreeBoardAction fbAction = new FreeBoardAction();
		DataBoardAction dbAction = new DataBoardAction();
		PhotoBoardAction pbAction = new PhotoBoardAction();
		
		menu.setFreeBoardMenus(fbAction.getFreeboardMenus(cono));
		menu.setDataBoardMenus(dbAction.getDataboardMenus(cono));
		menu.setPhotoBoardMenus(pbAction.getPhotoboardMenus(cono));
		
		CommunityLinkDAO clDAO = new CommunityLinkDAO();
		menu.setCommLinkMenus(clDAO.getCommunityLinks(cono));
		
		request.getSession().removeAttribute("menu");
		request.getSession().setAttribute("menu", menu);
	}
	
	
}
